// SETUP

#include endepisodegraphics_jester.txt

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function spinthewheel(sign, wheel) {
  var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.hide();
	
  wheel.x = 30;
  wheel.y = -30;
  play("spinthewheel");
	var s = wheel.show("spin1");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	wheel.hide();
}

// ACTORS

actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
actor("Warrior", 150, screenheight - 100, Col.LIGHTBLUE, LEFT, BOTTOM, "chat_warrior", "characters/warrior/charicon_warrior");

// INTRO

play("music_cutscene_lesscheery");

changebackground("intro_sign");

sign.y = -screenheight;
jester.y = -screenheight;
sign.show("loop");
jester.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(jester, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();

wait(1.5);

jester.show("talking");
speak("Jester", "Congratulations!");
speak("Jester", "Your very first victory!");
jester.show("idle");

speak("Warrior", "Am I super strong now?", "thinking");

jester.show("talking");
speak("Jester", "You’ll ALWAYS be super strong to me.");
speak("Jester", "But also... no, sorry.");
speak("Jester", "How it works is, every time you win|an episode, you get the chance to...");
speak("Jester", "SPIN... THE... WHEEL!");
speak("Jester", "And if the wheel ends up on a star?");
speak("Jester", "You get to leave the Dungeons and|take home your heart’s desire!");
speak("Jester", "Get ready to...");
speak("Jester", "SPIN THE WHEEL!");
speak("Jester", "SPIN THE WHEEL!");
speak("Jester", "You’re not chanting...");
jester.show("idle");

speak("Warrior", "Oh, sorry! SPIN THE WHEEL!", "personality");
speak("Warrior", "SPIN THE WHEEL!", "personality");

jester.show("talking");
speak("Jester", "Here we go...");
jester.show("idle");

jester.hide();

spinthewheel(sign, wheel);

signanimate(sign);

jester.show("talking");
speak("Jester", "Ahhhh, bad luck! No prize this time.");
speak("Jester", "But never mind, there are plenty|of episodes to come!");
jester.show("idle");

speak("Warrior", "SPIN THE WHEEL! SPIN THE WHEEL!", "personality");

jester.show("talking");
speak("Jester", "...you can stop chanting now.");
jester.show("idle");

gamecompletefromcutscene();
